package com.cn.system.tree.service;

import java.util.List;
import java.util.Map;

import com.cn.system.common.dto.UserInfo;
import com.cn.system.common.util.FrameworkConstants;
import com.cn.system.common.util.NumberUtils;


/**
 * 默认的抽象实现类，其中包含了一些string，int，long，boolean的转化方法，其他树的实现类最好继承这个类
 * 
 * @author zhangwei
 * 
 */
public abstract class AbstractDefaultTree implements ITreeService {

	protected Map<String, Object> params;

	@Override
	public List<Map<String, Object>> getTreeData(Map<String, Object> params) {
		this.params = params;
		return getTree(params);
	}
	
	@Override
	public String searchTreeData(Map<String, Object> params){
		this.params = params;
		return searchTree(params);
	}

	public abstract List getTree(Map<String, Object> params);
	
	public abstract String searchTree(Map<String, Object> params);

	public String getString(String key) {
		if (key == null) {
			return null;
		}
		return (String) params.get(key);
	}
	
	public boolean getBoolean(String key) {
		String value = getString(key);
		if ("true".equals(value)) {
			return true;
		}
		return false;
	}

	public int getInt(String key) {
		return NumberUtils.toInt(getString(key));
	}

	public Integer getInteger(String key) {
		return NumberUtils.createInteger(getString(key));
	}

	public Long getLong(String key) {
		return NumberUtils.createLong(getString(key));
	}

	public long getlong(String key) {
		return NumberUtils.toLong(getString(key));
	}
	public UserInfo getLoginUser() {
		return FrameworkConstants.getSessionUserInfo();
	}
}
